//
//  StatusOriginalView.m
//  CC
//
//  Created by Calvin on 5/19/15.
//  Copyright (c) 2015 Calvin. All rights reserved.
//

#import "StatusOriginalView.h"
#import "StatusOriginalFrame.h"
#import "StatusModel.h"
#import "UserModel.h"
#import "UIKit+AFNetworking.h"
#import "UIImage+Extension.h"

@interface StatusOriginalView()
@property (nonatomic,weak) UIImageView *iconView;
@property (nonatomic,weak) UILabel *nameLabel;
@property (nonatomic,weak) UILabel *textLabel;
@property (nonatomic,weak) UILabel *timeLabel;
@property (nonatomic,weak) UILabel *sourceLabel;
@property (nonatomic,weak) UIImageView *vipView;
@end

@implementation StatusOriginalView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //icon
        UIImageView *iconView = [[UIImageView alloc] init];
        [self addSubview:iconView];
        self.iconView = iconView;
        
        //nickName
        UILabel *nameLabel = [[UILabel alloc] init];
        nameLabel.textColor=CCColor(74, 102, 105);
        nameLabel.font = StatusOrginalNameFont;
        [self addSubview:nameLabel];
        self.nameLabel= nameLabel;
        
        //text
        UILabel *textLabel = [[UILabel alloc] init];
        textLabel.font = StatusOrginalTextFont;
        textLabel.numberOfLines=0;
        [self addSubview:textLabel];
        self.textLabel = textLabel;
        
        //time
        UILabel *timeLabel = [[UILabel alloc] init];
        [self addSubview:timeLabel];
        self.timeLabel = timeLabel;
        
        //source
        UILabel *sourceLabel = [[UILabel alloc] init];
        [self addSubview:sourceLabel];
        self.sourceLabel = sourceLabel;
        
        //VIP
        UIImageView *vipView=[[UIImageView alloc]init];
        vipView.contentMode=UIViewContentModeCenter;
        [self addSubview:vipView];
        self.vipView=vipView;
    }
    return self;
}

-(void)setOriginalFrame:(StatusOriginalFrame *)originalFrame
{
    _originalFrame = originalFrame;
    //set self frame
    self.frame = originalFrame.frame;
    //get data
    StatusModel *status = originalFrame.status;
    //set icon
    [self.iconView setImageWithURL:[NSURL URLWithString:status.user.profile_image_url] placeholderImage:[UIImage imageWithName:@"avatar_default_small"]];
    //set icon frame
    self.iconView.frame = originalFrame.iconFrame;
    
    //set nickName frame
    self.nameLabel.text =status.user.name;
    if (status.user.isVip)
    {
        self.nameLabel.textColor=[UIColor orangeColor];
        self.vipView.hidden=NO;
        self.vipView.frame=self.originalFrame.vipViewFrame;
        self.vipView.image=[UIImage imageWithName:[NSString stringWithFormat:@"common_icon_membership_level%d",status.user.mbrank]];
    }
    else
    {
        self.nameLabel.textColor=[UIColor blackColor];
        self.vipView.hidden=YES;
    }
    self.nameLabel.frame = originalFrame.nameFrame;
    
    //set text frame
    self.textLabel.text = status.text;
    self.textLabel.frame =originalFrame.textFrame;
    
    //set Time Frame
    self.timeLabel.text = status.created_at;
    self.timeLabel.frame = originalFrame.timeFrame;
    
    //set source frame
//    self.sourceLabel.text = status.source;
//    self.sourceLabel.frame = originalFrame.sourceFrame;
}
@end
